<html>
<%@ include file="../../common/taglibs.jsp"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		
		<title><fmt:message key="format.message.system" /></title>
	</head>
  <body>
  <script type="text/javascript">
  Ext.namespace('azure', 'azure.common');
  var datas;
  var num=1;
  var input;
  azure.common.enrty = function() {
  	/* ----------------------- private属性 ----------------------- */
  	var store_enrty;
  	var grid_enrty;
  	var rec_enrty;
  	var cm_enrty;
  	var tree_enrty;
  	var form_enrty, win_enrty;
  	var f_enable;
  	var gameText = '<fmt:message key="format.gameEntry.game" />';
  	var infoText = '<fmt:message key="format.message.prompt" />';
    var failToQueryText = '<fmt:message key="format.message.failToQuery" />';
    var inputLotteriesText = '<fmt:message key="format.gameEntry.inputLotteries" />';
	var saveLotteriesText = '<fmt:message key="format.gameEntry.saveLotteries" />';
	
  	/* ----------------------- private方法 ----------------------- */
  	function createTree() {
  		
  		var root = new Ext.tree.AsyncTreeNode(gameText);
  		tree_enrty = new Ext.tree.TreePanel({
  			width:200,
  			autoHeight : true,
  			
  			loader: new Ext.tree.TreeLoader({dataUrl:'PeriodGame_getGameToJson.action'}),
  			root: root
  		});
  		tree_enrty.on('click',function(node){
  			datas = node.attributes.tid;
  			form_enrty.form.reset(); 
  			num=1;
  			Ext.TaskMgr.start({
  			  run: function(){
			Ext.Ajax
            .request( {
                    url : 'PeriodGame_findGameTable.action',
                    scope : this,
                    success : function(resp, opts) {
                            var temp = Ext.util.JSON.decode(resp.responseText);
							var drawLotteryTime = temp.drawLotteryTime;
                		if(node.text!=gameText && temp.periodGame!=null){
                	       		form_enrty.setTitle(node.parentNode.attributes.text+"-->"+
			                        	       		node.text+"-->第"+
			                        	       		temp.periodGame.pgnum+"期-->"+
			                        	       		temp.periodGame.periodTime+
			                        	       		"&nbsp;&nbsp;&nbsp;&nbsp;<fmt:message key='format.gameEntry.LotteriesTime' />"+
			                        	       		drawLotteryTime+"<fmt:message key='format.gameEntry.Lotteriesunit' />");
                		}else {
                    		if(node.text!=gameText){
                    			form_enrty.setTitle(node.parentNode.attributes.text+"-->"+node.text);
                            }else{
                            	form_enrty.setTitle(node.text);
                            }
                				
                		}
                    },
                    failure : function(resp, opts) {
                            Ext.Msg.alert(infoText, failToQueryText);
                    },
                    params : {
                    	'gtno' : node.attributes.tid
                    }
            });
  		  },
		  interval: 1000
		});
  		});
  	}

		function func(value){
			if(num <= 20 && value!=""){
  			Ext.getCmp("lotteries"+num).setValue(value);
  			Ext.getCmp("inputNum").reset()
  			num++
  			}
		};
		
		
  	function createForm() {
  		form_enrty = new Ext.form.FormPanel({
			labelWidth : 65,
			title:gameText,
			frame : true,
			labelAlign : 'top',
			layout:'column',
			defaults: {
				layout: 'form',
				labelSeparator :'', 
				defaultType: 'textfield'
			},
			items : [
			{columnWidth:1,labelAlign :'left',labelWidth : 100, items:[ 
			  new Ext.form.NumberField({
			          fieldLabel : inputLotteriesText,
			          width : 25,
			          height:25,
			          enableKeyEvents: true, 
			          id:'inputNum',
						    decimalPrecision :0,
						    minValue: 1,
			          maxValue :80,
			          listeners :{
			          "keyup" : {            
				            fn: function(field,e){
				              if(field.getValue()>80){
				              	field.setValue(input);
				              }else{
				              	input =field.getValue();
				              }
				            }
				        },

                specialKey :function(field,e){
                if(field.isValid())
                    if (e.getKey() == Ext.EventObject.ENTER) func(field.getValue()); 
                }
			          
			          }
			          
			          
			   })     			
			]},
			{columnWidth:.04, items:[ 
				new Ext.form.TextField({
					fieldLabel : '1',
					name : 'lotteries1',
					id : 'lotteries1',
					width : 25,
					height:25
				}),
				new Ext.form.TextField({
					fieldLabel : '11',
					name : 'lotteries11',
					id : 'lotteries11',
					width : 25,
					height:25
				})   			
			]},
			{columnWidth:.04, items:[ 
			   new Ext.form.TextField({
			        fieldLabel : '2',
			        name : 'lotteries2',
			        id : 'lotteries2',
			        width : 25,
			        height:25
			}),
			   new Ext.form.TextField({
			        fieldLabel : '12',
			        name : 'lotteries12',
			        id : 'lotteries12',
			        width : 25,
			        height:25
			   })   			
			]},
			{columnWidth:.04, items:[ 
			       new Ext.form.TextField({
			        	fieldLabel : '3',
			        	name : 'lotteries3',
			        	id : 'lotteries3',
			        	width : 25,
			        	height:25
			       }),
			       new Ext.form.TextField({
			        	fieldLabel : '13',
			        	name : 'lotteries13',
			        	id : 'lotteries13',
			        	width : 25,
			        	height:25
			       })   			
			 ]},
			 {columnWidth:.04, items:[ 
				   new Ext.form.TextField({
				        fieldLabel : '4',
				        name : 'lotteries4',
				        id : 'lotteries4',
				        width : 25,
				        height:25
				   }),
				   new Ext.form.TextField({
				        fieldLabel : '14',
				        name : 'lotteries14',
				        id : 'lotteries14',
				        width : 25,
				        height:25
				   })   			
			]},
				{columnWidth:.04, items:[ 
					new Ext.form.TextField({
						fieldLabel : '5',
						name : 'lotteries5',
						id : 'lotteries5',
						width : 25,
						height:25
					}),
					new Ext.form.TextField({
						fieldLabel : '15',
						name : 'lotteries15',
						id : 'lotteries15',
						width : 25,
						height:25
					})   			
				]},
				{columnWidth:.04, items:[ 
				   new Ext.form.TextField({
				        fieldLabel : '6',
				        name : 'lotteries6',
				        id : 'lotteries6',
				        width : 25,
				        height:25
				}),
				   new Ext.form.TextField({
				        fieldLabel : '16',
				        name : 'lotteries16',
				        id : 'lotteries16',
				        width : 25,
				        height:25
				   })   			
				]},
				{columnWidth:.04, items:[ 
				       new Ext.form.TextField({
				        	fieldLabel : '7',
				        	name : 'lotteries7',
				        	id : 'lotteries7',
				        	width : 25,
				        	height:25
				       }),
				       new Ext.form.TextField({
				        	fieldLabel : '17',
				        	name : 'lotteries17',
				        	id : 'lotteries17',
				        	width : 25,
				        	height:25
				       })   			
				 ]},
				 {columnWidth:.04, items:[ 
					   new Ext.form.TextField({
					        fieldLabel : '8',
					        name : 'lotteries8',
					        id : 'lotteries8',
					        width : 25,
					        height:25
					   }),
					   new Ext.form.TextField({
					        fieldLabel : '18',
					        name : 'lotteries18',
					        id : 'lotteries18',
					        width : 25,
					        height:25
					   })   			
				]},
				{columnWidth:.04, items:[ 
				   	  new Ext.form.TextField({
				   		   fieldLabel : '9',
				   		   name : 'lotteries9',
				   		   id : 'lotteries9',
				   		   width : 25,
				   		   height:25
					   }),
				   	   new Ext.form.TextField({
				   		    fieldLabel : '19',
				   			name : 'lotteries19',
				   			id : 'lotteries19',
				   			width : 25,
				   			height:25
				   	  })   			
				 ]}	,
				{columnWidth:.04, items:[ 
					   new Ext.form.TextField({
							fieldLabel : '10',
							name : 'lotteries10',
							id : 'lotteries10',
							width : 25,
							height:25
					    }),
					   new Ext.form.TextField({
							fieldLabel : '20',
							name : 'lotteries20',
							id : 'lotteries20',
							width : 25,
							height:25
					   })   			
				]}					
			],
			buttons :[{text: saveLotteriesText,handler :enrtySave}]
		});
  	}
  	
  	// 创建主界面
  	function createUI() {
  		createForm();
  		createTree();
  		new Ext.Panel({
  			height:535,
  			renderTo: 'enrtyDiv',
  			layout:'border',
  			items: [
  				{region: 'west', width: 200, items: tree_enrty},
  				{region: 'center', items: form_enrty}
  			]
  		});
  	}

  	function enrtySave(btn){
  		var lotteries = [];
  		for(var i=1;i<=20;i++){
  			var lotteriesid = "lotteries"+i
  			var lotteriesNum = Ext.getCmp(lotteriesid).getValue();
  			lotteries.push(lotteriesNum);
  		}
			if(form_enrty.getForm().isValid()){
  				btn.disable();
  				form_enrty.getForm().submit({
  	  				url:'PeriodGame_savePeriodGameResult.action',
  					method : 'POST',
  					waitMsg : '<fmt:message key="format.message.saving"/>',
  					successProperty : false,
  					params:{'lotteries':lotteries,gtno:datas},
  					success : function() {
  						Ext.Msg.alert('<fmt:message key="format.message.success"/>', 
  							'<fmt:message key="format.message.save.success"/>',function() {
  							btn.enable();
  						});
  					},
  					failure : function() {
  						Ext.Msg.alert('<fmt:message key="format.message.failure"/>', 
  							'<fmt:message key="format.message.save.failure"/>');
  							btn.enable();
  					}
  				});
  				}
		
  	}
  	/* ----------------------- public方法 ----------------------- */
  	return {
  		//初始化
  		init : function() {
  			createUI();
  		}
  	};
  }();
  Ext.EventManager.onDocumentReady(azure.common.enrty.init, azure.common.enrty, true);
  </script>
  	<div id="enrtyDiv"></div>
  </body>
</html>
